//
//  WFBaseViewController.m
//  谷居
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 刘万方. All rights reserved.
//

#import "WFBaseViewController.h"
#import "WFSettingWindow.h"
#import "WFCollectionVC.h"
#import "WFSetViewController.h"
@interface WFBaseViewController ()<WFSettingWindowDelegate>
@property (nonatomic, retain) UIButton *photoButton; /** 头像. */

@property (nonatomic, retain) WFSettingWindow *settingWindow;

@property (nonatomic, assign) BOOL  isAppeared;

@property (nonatomic, retain) WFCollectionVC *collctionVC; /** 收藏viewcontroller. */

@property (nonatomic, retain) WFSetViewController *setVc;
@end

@implementation WFBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
#pragma mark - 添加夜间模式
    [self setColor];
    [self addObserver];

    [self createSettingView];
    [self createPhotoImageView];
    
//    self.navigationController.navigationBar.translucent = NO;

    // Do any additional setup after loading the view.
   }



#pragma mark - 免费设计按钮
- (void)createFreeDesignButton {
    
    __block __typeof(&*self)weakSelf = self;
    _freedesignButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_freedesignButton mas_makeConstraints:^(MASConstraintMaker *make) {
        NSLog(@"添加freebutton.");
        make.right.equalTo(weakSelf.view).offset(-20);
        make.bottom.equalTo(weakSelf.view).offset(-80);
        make.size.mas_equalTo(CGSizeMake(60, 60));
        [self.view addSubview:_freedesignButton];
    }];
    [_freedesignButton setBackgroundImage:[UIImage imageNamed:@"免费设计.png"] forState:UIControlStateNormal];
    [_freedesignButton addTarget:self action:@selector(clickFreeDesign:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)clickFreeDesign:(UIButton *)button {
    NSLog(@"免费设计按钮被点击. ");
}



#pragma mark - 设置Setting界面
- (void)createSettingView {
    _settingWindow = [[WFSettingWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    _settingWindow.delegate = self;
}
- (void)pushLikeCollectionVC {
    _collctionVC = [[WFCollectionVC alloc] init];
    [self.navigationController  pushViewController:_collctionVC animated:YES];
    [_collctionVC release];
    

}
- (void)pushSetVC {
    _setVc = [[WFSetViewController alloc] init];
    [self.navigationController pushViewController:_setVc animated:YES];
    [_setVc release];
}
- (void)push:(UIViewController *)vc {
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - 头像按钮
- (void)createPhotoImageView {
    /** 先创建一个button. */
    _photoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _photoButton.frame = CGRectMake(0, 0, 32, 32);
    [_photoButton setBackgroundImage:[UIImage imageNamed:@"头像.png"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_photoButton];
    
    /** 添加点击方法. */
    [_photoButton addTarget:self action:@selector(clickPhoto:) forControlEvents:UIControlEventTouchUpInside];
}


#pragma mark - 头像按钮消失
- (void)clickPhoto:(UIButton *)button {
//    [self.delegate makeWindowVisable:self.view.window];
    if (!self.isAppeared) {
        [_settingWindow show];
        
        NSLog(@"头像被点击. ");
    } else {
        
    }
    
}


//- (instancetype)init {
//    self = [super init];
//    if (self) {
//    }
//    return self;
//}
- (void)setColor {
    if (!IS_LONG) {
        self.view.backgroundColor = DAY_COLOR;
    } else {
        self.view.backgroundColor = NIGHT_COLOR;
    }
    
}

- (void)addObserver {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeToNight:) name:@"夜间模式" object:nil];
    
}
-(void)changeToNight:(NSNotification *)sender {
    if (!IS_LONG) {
        self.view.backgroundColor = NIGHT_COLOR;
    } else {
        self.view.backgroundColor = DAY_COLOR;
    }
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    [super dealloc];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
